<template>
  <div class="app-container">
    <div id="map"></div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="门店名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入门店名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:store:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:store:del']"
          >批量删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-setting"
          size="mini"
          :disabled="multiple"
          @click="handleChargeBack"
          v-hasPermi="['business:store:chargeBack']"
          >退单规则</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleScoringRules"
          v-hasPermi="['business:store:evaluationRule']"
          >评价规则</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:store:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="storeList"
      @selection-change="handleSelectionChange"
      max-height="650px"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column
        label="门店图片"
        align="center"
        prop="images"
        width="200"
      >
        <template slot-scope="scope">
          <image-preview :src="scope.row.images" :width="100" :height="100" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="收款码图片" align="center" prop="collectionCode" width="200">
      <template slot-scope="scope">
        <image-preview :src="scope.row.collectionCode" :width="100" :height="100" />
      </template>
      </el-table-column> -->
 

      <el-table-column
        label="所属区域"
        align="center"
        :show-overflow-tooltip="true"
        prop="regionName"
        width="120"
      />
      <el-table-column
        label="门店名称"
        align="center"
        :show-overflow-tooltip="true"
        prop="storeName"
        width="120"
      />
      <el-table-column
        label="门店编号"
        align="center"
        :show-overflow-tooltip="true"
        prop="storeCode"
        width="120"
      />
     
      <el-table-column
        label="退单规则"
        align="center"
        prop="chargebackName"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.chargebackName ? scope.row.chargebackName : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="评价规则"
        align="center"
        prop="evaluationRuleName"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.evaluationRuleName ? scope.row.evaluationRuleName : "暂无"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="营业状态" align="center" prop="isInitiate">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.status ? '#808080' : '#FF5733' }">
            {{
              scope.row.status == 1
                ? "营业中"
                : scope.row.status == 2
                ? "筹备中"
                : "休息中"
            }}
          </span>
        </template>
      </el-table-column>
      
      <!-- <el-table-column label="负责人名称" align="center" prop="principalName">
        <template slot-scope="scope">
          <span>{{
            scope.row.principalName ? scope.row.principalName : "暂无"
          }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        label="会员类型"
        align="center"
        :show-overflow-tooltip="true"
        prop="memberType"
        width="120"
      >
        <template slot-scope="scope">
          <span>{{
            scope.row.memberType == "1" ? "会员价格" : "会员折扣"
          }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="商家APIKEY" align="center" prop="apiKey" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.apikey ? scope.row.apikey : '暂无' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加密key" align="center" prop="key">
        <template slot-scope="scope">
          <span>{{ scope.row.key ? scope.row.key : '暂无' }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="联系电话" align="center" prop="phoneNumber">
        <template slot-scope="scope">
          <span>{{
            scope.row.phoneNumber ? scope.row.phoneNumber : "暂无"
          }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="详细地址"
        align="center"
        :show-overflow-tooltip="true"
        prop="detail"
      />
      <!-- <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" /> -->
      <!-- <el-table-column label="简介" align="center" prop="intro" /> -->
      <el-table-column label="营业开始时间" align="center" prop="openingTime" />
      <el-table-column label="营业结束时间" align="center" prop="closingTime" />
      <el-table-column label="技师休息时间" align="center" prop="restTime" />
      <el-table-column
        label="提前预约天数"
        align="center"
        prop="advanceReservation"
      />
      <el-table-column label="状态" align="center" prop="isInitiate">
        <template slot-scope="scope">
          <span
            :style="{ color: scope.row.isInitiate ? '#808080' : '#FF5733' }"
            >{{ scope.row.isInitiate == "1" ? "上架" : "下架" }}</span
          >
        </template>
      </el-table-column>

      <el-table-column
        label="小程序端是否显示"
        align="center"
        prop="minProIsShow"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.minProIsShow == "1" ? "是" : "否" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />

      <el-table-column label="修改人" align="center" prop="updateBy" />
      <el-table-column label="修改时间" align="center" prop="updateTime" />

      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:store:edit']"
            >修改</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handReset(scope.row)"
            v-hasPermi="['system:store:edit']"
          >重置密码</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload2"
            @click="handleGround(scope.row, (isInitiate = 1))"
            :disabled="scope.row.isInitiate === 1"
            v-hasPermi="['business:store:put']"
            >上架</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleGround(scope.row, (isInitiate = 2))"
            :disabled="scope.row.isInitiate === 2"
            v-hasPermi="['business:store:offShelf']"
            >下架</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:store:del']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改门店对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="900px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <!-- <el-col :span="24"> -->
        <el-form-item label="门店图片" prop="images">
          <image-upload v-model="form.images" />
        </el-form-item>
        <el-row>
          <!-- <el-form-item
            label="收款二维码"
            v-if="title == '修改门店'"
            prop="collectionCode"
          >
            <image-upload v-model="form.collectionCode" />
          </el-form-item> -->
        </el-row>
        <!-- </el-col> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属区域" prop="regionId">
              <el-select
                clearable
                v-model="form.regionId"
                @change="changeRegion"
              >
                <el-option
                  v-for="(item, index) of region"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省市区" prop="addressAll">
              <el-cascader
                v-model="form.addressAll"
                :options="options"
                @change="handleChange"
                placeholder="请输入省市区"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="优惠类型" prop="isInitiate">
              <el-select clearable v-model="form.memberType">
              <el-option v-for="(item,index) of favourable" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option>
              </el-select>
            </el-form-item>
         </el-col> -->
          <el-col :span="12">
            <el-form-item label="营业状态" prop="status">
              <el-select clearable v-model="form.status">
                <el-option
                  v-for="(item, index) of statusList"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店名称" prop="storeName">
              <el-input
                v-model="form.storeName"
                placeholder="请输入门店名称"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="form.status == 3 || form.status == 2">
          <el-col :span="12">
            <el-form-item label="预计开业时间" prop="startBusinessTime">
              <!-- <el-input v-model="form.startBusinessTime" placeholder="请输入商家APIKEY" style="width: 220px" /> -->

              <el-date-picker
                clearable
                v-model="form.startBusinessTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择预计开业时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.status == 3">
            <el-form-item label="暂停原因" prop="key">
              <el-input
                v-model="form.pauseCause"
                type="textarea"
                placeholder="请输入暂停原因"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="支付appId" prop="payAppId">
              <el-input
                v-model="form.payAppId"
                placeholder="请输入支付appId"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>

        </el-row>


           <el-row>
  
          <el-col :span="12">
            <el-form-item label="支付terminaCode" prop="payTerminaCode">
              <el-input
                v-model="form.payTerminaCode"
                placeholder="请输入支付terminaCode"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="支付key" prop="key">
              <el-input
                v-model="form.key"
                placeholder="请输入支付key"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="讯飞appid" prop="xfAppid">
              <el-input
                v-model="form.xfAppid"
                placeholder="请输入讯飞appid"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="讯飞apisecret" prop="xfApisecret">
              <el-input
                v-model="form.xfApisecret"
                placeholder="请输入讯飞apisecret"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <!-- <el-col :span="12">
            <el-form-item label="门店收款码" prop="storeName">
             <el-input v-model="form.paymentCode" placeholder="请输入门店名称" style='width:220px'/>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phoneNumber">
              <el-input
                v-model="form.phoneNumber"
                placeholder="请输入联系电话"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店编号" prop="storeCode">
              <el-input
                v-model="form.storeCode"
                placeholder="请输入门店编号"
                style="width: 220px"
                maxlength="6"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="营业时间" prop="openingTime">
              <el-time-picker
                v-model="form.openingTime"
                value-format="HH:mm"
                format="HH:mm"
                placeholder="起始时间"
              >
              </el-time-picker>
              --
              <el-time-picker
                v-model="form.closingTime"
                value-format="HH:mm"
                format="HH:mm"
                placeholder="结束时间"
              >
              </el-time-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="状态" prop="isInitiate">
              <el-select clearable v-model="form.isInitiate">
                <el-option
                  v-for="(item, index) of List"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="固定电话" prop="landlinePhone">
              <el-input
                v-model="form.landlinePhone"
                placeholder="请输入联系电话"
                style="width: 220px"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" style="display: flex">
            <el-form-item label="技师休息时间" prop="restTime">
              <el-input
                v-model="form.restTime"
                placeholder="请输入休息时间"
                style="width: 220px"
              />
            </el-form-item>
            <span class="unit">分钟</span>
          </el-col>
          <el-col :span="12" style="display: flex">
            <el-form-item label="提前预约天数" prop="advanceReservation">
              <el-input
                type="number"
                v-model="form.advanceReservation"
                placeholder="请输入预约天数"
                style="width: 220px"
              />
            </el-form-item>
            <span class="unit">天</span>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="详细地址" prop="detail">
              <el-input
                type="textarea"
                v-model="form.detail"
                placeholder="请输入详细地址"
                @blur="setPlace"
                style="width: 700px"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="经度" prop="longitude">
              <el-input v-model="form.longitude" placeholder="请输入经度" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="纬度" prop="latitude">
              <el-input v-model="form.latitude" placeholder="请输入纬度" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button
              type="text"
              style="margin-left: 20px"
              @click="openNewWindow"
              >获取经纬度</el-button
            >
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="小程序端显示" prop="minProIsShow">
              <el-select clearable v-model="form.minProIsShow">
                <el-option
                  v-for="(item, index) of isShowList"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="简介" prop="intro">
          <el-input
            v-model="form.intro"
            type="textarea"
            placeholder="请输入内容"
            style="width: 700px"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 退单规则弹框 -->
    <el-dialog
      :title="title"
      :visible.sync="chargeBackDialog"
      width="950px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-table
        v-loading="loading"
        :data="chargeBackList"
        @select="handleDialogChange"
        ref="multipleTable"
        class="chargeBackTable"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="适用门店"
          align="center"
          prop="storeName"
          width="120"
        />
        <el-table-column
          label="退单规则名称"
          align="center"
          prop="chargebackName"
        />
        <el-table-column
          label="自动退款时间段"
          align="center"
          prop="chargebackTime"
        />
        <el-table-column
          label="退款比例"
          align="center"
          prop="chargebackScale"
        />
        <el-table-column label="状态" align="center" prop="status" width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.status == "1" ? "启用" : "禁用" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <pagination
          v-show="total > 0"
          :total="chargeBacktotal"
          :page.sync="chargeBackPageNum"
          :limit.sync="chargeBackPageSize"
          @pagination="getChargeBackList"
        />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="chargeBackSubmit">确 定</el-button>
        <el-button @click="chargeBackCancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :title="title"
      :visible.sync="ScoringRulesDialog"
      width="950px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-table
        v-loading="loading"
        :data="ScoringRulesList"
        @select="handleSRDialogChange"
        ref="multipleTable"
        class="chargeBackTable"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="规则名称" align="center" prop="ruleName" />
        <el-table-column label="分数" align="center" prop="score" />

        <el-table-column
          label="优惠券"
          align="center"
          prop="ticketId"
          width="150"
        >
          <template slot-scope="scope">
            <span>{{ findName(scope.row.ticketId) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="优惠券数量" align="center" prop="number" />
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <pagination
          v-show="total > 0"
          :total="ScoringRulestotal"
          :page.sync="ScoringRulesPageNum"
          :limit.sync="ScoringRulesPageSize"
          @pagination="ScoringRulesList"
        />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ScoringRulesSubmit">确 定</el-button>
        <el-button @click="ScoringRulesCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStore,
  getStore,
  delStore,
  addStore,
  updateStore,
  listChina,
  listResetPwd,
  listregion,
  upDateChargeback,
  getByOrderId,
} from "@/api/system/store";
import { listRule, getPresenterList } from "@/api/system/rule/rule";

import { listchargeback } from "@/api/system/orderList/ChargebackRule";
export default {
  name: "Store",
  data() {
    return {
      presenterArr: [],
      ScoringRulesDialog: false,
      map: null,
      local: null,
      mk: null,
      latitude: "",
      longitude: "",
      keyWords: "",
      result: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //退单规则条数
      chargeBacktotal: 0,
      // 门店表格数据
      storeList: [],
      //退单规则表格数据
      chargeBackList: [],
      ScoringRulesList: [],
      ScoringRulestotal: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示退单规则弹框
      chargeBackDialog: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        county: null,
        countyString: null,
        detail: null,
        longitude: null,
        latitude: null,
        startBusinessTime: null,
        intro: null,
        images: null,
        collectionCode: null,
        status: null,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        storeCode: null,
        landlinePhone: null,
        minProIsShow: null,
      },
      chargeBackPageNum: 1,
      chargeBackPageSize: 10,
      ScoringRulesPageNum: 1,
      ScoringRulesPageSize: 10,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        images: [{ required: true, message: "请选择图片", trigger: "blur" }],
        collectionCode: [
          { required: true, message: "请上传收款码", trigger: "blur" },
        ],
        storeName: [
          { required: true, message: "请输入门店名称", trigger: "blur" },
          {
            min: 1,
            max: 10,
            message: "长度在 1 到 10 个字符",
            trigger: "blur",
          },
        ],
        phoneNumber: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: "手机号码格式不正确",
            trigger: "blur",
          },
        ],
        // landlinePhone: [
        //   { required: true, message: '请输入固定电话', trigger: 'blur' },
        //   { pattern: /^\d{3,4}-\d{7,8}$/, message: '电话格式不正确', trigger: 'blur' }
        // ],
        openingTime: [
          { required: true, message: "请选择营业时间", trigger: "blur" },
        ],
        isInitiate: [{ required: true, message: "请选择", trigger: "blur" }],
        status: [{ required: true, message: "请选择", trigger: "blur" }],
        addressAll: [
          { required: true, message: "请输入省市区", trigger: "blur" },
        ],
        regionId: [
          { required: true, message: "请输入所属区域", trigger: "blur" },
        ],
        detail: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
          {
            min: 1,
            max: 30,
            message: "长度在 1 到 30 个字符",
            trigger: "blur",
          },
        ],
        intro: [
          { required: true, message: "请输入简介", trigger: "blur" },
          {
            min: 1,
            max: 1000,
            message: "长度在 1 到 1000 个字符",
            trigger: "blur",
          },
        ],
        paymentCode: [
          { required: true, message: "请输入门店收款码", trigger: "blur" },
          {
            pattern: /^[0-9A-Za-z]{6,12}$/,
            message: "收款码格式不正确",
            trigger: "blur",
          },
        ],
        restTime: [
          { required: true, message: "请输入技师休息时间", trigger: "blur" },
          { pattern: /^[0-9]\d*$/, message: "请输入正确数据", trigger: "blur" },
        ],
        storeCode: [
          { required: true, message: "请输入门店编号", trigger: "blur" },
          {
            pattern: /^[A-Za-z0-9]{1,8}$/,
            message: "格式不正确",
            trigger: "blur",
          },
        ],
        latitude: [{ required: true, message: "请输入纬度", trigger: "blur" }],
        longitude: [{ required: true, message: "请输入经度", trigger: "blur" }],
        minProIsShow: [
          {
            required: true,
            message: "请选择是否展示小程序端",
            trigger: "blur",
          },
        ],
      },
      options: [],
      List: [
        {
          key: 1,
          value: "上架",
        },
        {
          key: 2,
          value: "下架",
        },
      ],
      statusList: [
        {
          key: 1,
          value: "营业中",
        },
        {
          key: 2,
          value: "筹备中",
        },
        {
          key: 3,
          value: "休息中",
        },
      ],
      favourable: [
        {
          key: 1,
          value: "优惠价",
        },
        {
          key: 2,
          value: "折扣价",
        },
      ],
      region: [],
      chargeBackIds: [],
      ScoringRulesIds: [],
      id: null,
      isShowList: [
        {
          key: "1",
          value: "是",
        },
        {
          key: "2",
          value: "否",
        },
      ],
    };
  },
  created() {
    this.getList();
    this.listChina();
    this.listregion();
    this.GetPresenterArr();
  },
  mounted() {
    // this.initMap();
  },
  methods: {
    findName(item) {
      const aa = this.presenterArr.find((el) => el.id == item);
      if (aa) {
        return aa.name;
      }
    },
    GetPresenterArr() {
      getPresenterList().then((res) => {
        console.log(res.rows);
        this.presenterArr = res.rows;
      });
    },
    openNewWindow() {
      window.open("https://lbs.qq.com/getPoint", "_blank");
    },
    //查询退单规则列表
    getChargeBackList() {
      this.loading = true;
      const params = {
        pageNum: this.chargeBackPageNum,
        pageSize: this.chargeBackPageSize,
        storeId: null,
      };
      listchargeback(params).then((response) => {
        this.chargeBackList = response.rows;
        this.chargeBacktotal = response.total;
        this.loading = false;
      });
    },
    //退单规则多选
    // handleDialogChange(selection){
    //   this.chargeBackIds = selection.map((item) => item.id);
    //   this.single = selection.length !== 1;
    //   this.multiple = !selection.length;
    // },
    //退单规则单选
    handleDialogChange(selection, row) {
      this.chargeBackIds = row.id;
      this.multipleSelection = row;
      this.$refs.multipleTable.clearSelection(); //先清空选中状态，selection值还在
      if (selection.length === 0) {
        //这里状态为勾选
        return;
      }
      this.$refs.multipleTable.toggleRowSelection(row, true); //用于切换某行选中状态
    },
    //评价规则单选
    handleSRDialogChange(selection, row) {
      this.ScoringRulesIds = row.id;
      this.multipleSelection = row;
      this.$refs.multipleTable.clearSelection(); //先清空选中状态，selection值还在
      if (selection.length === 0) {
        //这里状态为勾选
        return;
      }
      this.$refs.multipleTable.toggleRowSelection(row, true); //用于切换某行选中状态
    },
    //点击退单规则按钮
    handleChargeBack(row) {
      this.chargeBackDialog = true;
      this.title = "退单规则";
      this.id = row.id;
      this.getChargeBackList();
      1;
    },
    //点击评价规则按钮
    handleScoringRules() {
      this.ScoringRulesDialog = true;
      this.title = "评价规则";
      this.getScoringRulesList();
    },
    //查询评价规则列表
    getScoringRulesList() {
      this.loading = true;
      const params = {
        pageNum: 1,
        pageSize: 10,
      };
      listRule(params).then((response) => {
        this.ScoringRulesList = response.rows;
        this.ScoringRulestotal = response.total;
        this.loading = false;
      });
    },
    listregion() {
      listregion().then((res) => {
        this.region = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.regionName,
          };
        });
      });
    },
    changeRegion(value) {
      const selectedOption = this.region.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;

      this.form.regionName = selectedValue;
    },
    initMap() {
      this.map = new BMap.Map("map");
      let point = new BMap.Point(116.404, 39.915);
      this.map.centerAndZoom(point, 12);
      this.map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
      this.map.addControl(new BMap.NavigationControl());
    },
    // 点击定位-定位到当前位置
    // 搜索地址
    setPlace() {
      this.local = new BMap.LocalSearch(this.map, {
        onSearchComplete: this.searchPlace,
      });
      this.local.search(this.form.detail);
    },
    searchPlace() {
      if (this.local.getResults() != undefined) {
        this.map.clearOverlays(); //清除地图上所有覆盖物
        if (this.local.getResults().getPoi(0)) {
          let point = this.local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
          this.map.centerAndZoom(point, 18);
          // this.handleMarker(this, point)
          console.log(point, 1111);
          console.log("经度：" + point.lng + "--" + "纬度" + point.lat);
          this.form.longitude = point.lng;
          this.form.latitude = point.lat;
          this.latitude = point.lat;
          this.longitude = point.lng;
        } else {
          this.$message.error("未匹配到地点!");
        }
      } else {
        this.$message.error("未找到搜索结果!");
      }
    },
    // fixedPos() {
    //     const _this = this
    //     const geolocation = new BMap.Geolocation()
    //     this.confirmLoading = true
    //     geolocation.getCurrentPosition(function(r) {
    //       if (this.getStatus() == BMAP_STATUS_SUCCESS) {
    //         _this.handleMarker(_this, r.point)
    //         let myGeo = new BMap.Geocoder()
    //         myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), function(result) {
    //           _this.confirmLoading = false
    //           if (result) {
    //             _this.latitude = result.point.lat
    //             _this.longitude =  result.point.lng
    //           }
    //         })
    //       } else {
    //         _this.$message.error('failed' + this.getStatus())
    //       }
    //     })
    // },
    // 设置标注
    // handleMarker(obj, point) {
    //   obj.mk = new BMap.Marker(point)
    //   obj.map.addOverlay(obj.mk)
    //   obj.mk.enableDragging() // 可拖拽
    //   obj.mk.addEventListener('dragend', function(e) { // 监听标注的拖拽，获取拖拽后的经纬度
    //     this.latitude = point.lat
    //     this.longitude =  point.lng
    //   })
    //   obj.map.panTo(point)

    // },
    // blurDetail(){
    //   const geocoder = new BMap.Geocoder();
    //   geocoder.getPoint(this.form.detail, point => {
    //     if (point) {
    //       this.result = `经度：${point.lng}，纬度：${point.lat}`;
    //     } else {
    //       this.result = '地址解析失败';
    //     }
    //   }, '北京市');
    // },
    listChina() {
      listChina().then((res) => {
        this.options = res.data.map((rItem) => {
          return {
            value: rItem.id,
            label: rItem.cityName,
            children: rItem.children.map((item) => {
              return {
                value: item.id,
                label: item.cityName,
                children: item.children.map((stem) => {
                  return {
                    value: stem.id,
                    label: stem.cityName,
                  };
                }),
              };
            }),
          };
        });
      });
    },
    handleChange() {},

    /** 查询门店列表 */
    getList() {
      this.loading = true;
      listStore(this.queryParams).then((response) => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        storeName: null,
        phoneNumber: null,
        province: null,
        provinceString: null,
        city: null,
        cityString: null,
        county: null,
        countyString: null,
        detail: null,
        longitude: null,
        pauseCause: null,
        latitude: null,
        intro: null,
        images: null,
        collectionCode: null,
        status: null,
        isInitiate: null,
        openingTime: null,
        closingTime: null,
        createTime: null,
        updateTime: null,
        storeCode: null,
        landlinePhone: null,
        minProIsShow: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      console.log(this.single, "this.single");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.listregion();
      this.open = true;
      this.title = "添加门店";
    },
    // 上下架
    handleGround(row, isInitiate) {
      const params = {
        id: row.id,
        isInitiate: isInitiate,
      };
      this.$confirm(
        `此操作将${isInitiate === 1 ? "上架" : "下架"}该数据, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          updateStore(params).then((res) => {
            this.$message({
              type: "success",
              message: `${isInitiate === 1 ? "上架" : "下架"}成功!`,
            });
            this.getList();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消上下架",
          });
        });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getStore(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门店";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (this.form.openingTime > this.form.closingTime) {
        this.$modal.msgWarning("开始时间大于结束时间");
        return;
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateStore(this.form).then((response) => {
              if (response.code == 200) {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addStore(this.form).then((response) => {
              if (response.code == 200) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    //门店规则提交
    chargeBackSubmit() {
      const params = {
        storeIds: this.ids,
        chargebackIds: this.chargeBackIds,
      };
      upDateChargeback(params).then((response) => {
        if (response.code == 200) {
          this.chargeBackDialog = false;
          this.$message.success(response.msg);
          this.getList();
        }
      });
    },
    //评价规则提交
    ScoringRulesSubmit() {
      const params = {
        storeIds: this.ids,
        evaluationRuleId: this.ScoringRulesIds,
      };
      // console.log(this.ids,'this.ids',params);

      getByOrderId(params).then((response) => {
        if (response.code == 200) {
          this.ScoringRulesDialog = false;
          this.$message.success(response.msg);
          this.getList();
        }
      });
    },
    //门店规则取消
    chargeBackCancel() {
      this.chargeBackDialog = false;
    },
    //评价规则取消
    ScoringRulesCancel() {
      this.ScoringRulesDialog = false;
    },
    handReset(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认重置门店编号为"' + ids + '"的数据项？')
        .then(function () {
          return listResetPwd({ userId: ids });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("重置成功");
        })
        .catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除门店编号为"' + ids + '"的数据项？')
        .then(function () {
          return delStore(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/store/export",
        {
          ...this.queryParams,
        },
        `store_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.el-dialog__footer {
  text-align: center;
}

.chargeBackTable thead .el-checkbox {
  display: none;
}

.unit {
  margin-top: 8px;
  margin-left: 8px;
}
</style>
